<template>
	<view>
		<p style="margin-top: 20px;font-size: 16px;margin-left: 15px;">请选择就诊人</p>

		<uni-card :is-shadow="false" style="background-color:#F5F9FF;" @click="ToSelectArea1">
			<view>
				<view style="float: left;width:150px;height:70px;">
					<view>
						<p style="font-size: 18px;margin-bottom: 8px;float: left;">{{thePatient1.name}}
						</p>
						<u-tag style="width: 38px;float: left;margin-left: 10px;" size="mini"
							:text="thePatient1.relation" shape="circle"></u-tag>
					</view>
					<p>{{thePatient1.number}}</p>
				</view>
				<view style="float: right;height:50px;">
					默认就诊人
				</view>
			</view>
		</uni-card>


		<view v-for="(r,index) in thePatient2" :key="index">
			<uni-card :is-shadow="false" style="background-color:#F5F9FF;" @click="ToSelectArea2(r)">
				<view>
					<view style="float: left;width:150px;height:70px;">
						<view>
							<p style="font-size: 18px;margin-bottom: 8px;float: left;">{{r.name}}
							</p>
							<u-tag style="width: 38px;float: left;margin-left: 10px;" size="mini" :text="r.relation"
								shape="circle"></u-tag>
						</view>
						<p>{{r.number}}</p>
					</view>

				</view>
			</uni-card>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userId: 1,
				thePatient1: '',
				thePatientId:'',
				thePatient2:[],

			}
		},
		onLoad() {
			//this.userId = uni.getStorageSync('userId')
			console.log(this.userId)
			
			//根据userId查询该用户下的所有就诊人
			this.getThePatientById();
		},
		methods: {
			getThePatientById() {
				this.$axios.get("/user/user/the-patient/getThePatientById/" + this.userId).then((
						res) => {
						//response 接口返回数据
						console.log("成功")

						this.thePatient1 = res.data.data.thePatient
						this.thePatient2 = res.data.data.list
						console.log(this.thePatient2)
					}) //请求成功
					.catch((error) => {
						console.log(error);
					}); //请求失败
			},
			ToSelectArea1() {
				console.log(this.thePatient1.id)
				//跳转到登录页面
				uni.setStorage({
					key: 'patient',
					data: this.thePatient1,
					success() {
						console.log('就诊人存储成功')
					}
				})
				let url;
				uni.getStorage({
					key: 'selectPatientAfterUrl',
					success:function(res){
						//alert(JSON.stringify(res))
						url=res.data
					}
				})
				
				setTimeout(() => {
					uni.setStorage({
						key: 'selectAreaAfterUrl',
						data: '/pages/appointment/nucleicAcid',
						success() {
							console.log('地区2选择后跳转设置成功')
						}
					})
					alert(url)
					uni.navigateTo({
						url: url
					})
				})
			},
			ToSelectArea2(r) {
				//console.log("触发跳转")
				//跳转到登录页面
				
				this.thePatientId = r.id
				//alert(this.thePatientId)
				uni.setStorage({
					key: 'patient',
					data: r,
					success() {
						console.log('就诊人存储成功')
					}
				})
				let url;
				uni.getStorage({
					key: 'selectPatientAfterUrl',
					success:function(res){
						//alert(JSON.stringify(res))
						url=res.data
					}
				})
				uni.setStorage({
					key: 'selectAreaAfterUrl',
					data: '/pages/appointment/nucleicAcid',
					success() {
						console.log('地区2选择后跳转设置成功')
					}
				})
				setTimeout(() => {
					uni.navigateTo({
						url: url
					})
				})
			}
		}
	}
</script>

<style>

</style>
